package com.pac.questionnaire.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.common.page.Page;
import com.common.page.PageContext;
import com.common.tools.StringTools;
import com.common.util.LogicException;
import com.common.util.MsgKeyContent;
import com.common.util.SessionKeyContent;
import com.pac.questionnaire.QuestionnaireKeyContent;
import com.pac.questionnaire.bean.QuestionBean;
import com.pac.questionnaire.bean.QuestionOptionBean;
import com.pac.questionnaire.bean.QuestionnaireAnswerBean;
import com.pac.questionnaire.bean.QuestionnaireAnswerFileBean;
import com.pac.questionnaire.bean.QuestionnaireBean;
import com.pac.questionnaire.bean.QuestionnaireDiagnosisBean;
import com.pac.questionnaire.bean.QuestionnaireHospitalBean;
import com.pac.questionnaire.bean.QuestionnaireQuestionRelBean;
import com.pac.questionnaire.service.QuestionOptionService;
import com.pac.questionnaire.service.QuestionService;
import com.pac.questionnaire.service.QuestionnaireAnswerFileService;
import com.pac.questionnaire.service.QuestionnaireAnswerService;
import com.pac.questionnaire.service.QuestionnaireDiagnosisService;
import com.pac.questionnaire.service.QuestionnaireHospitalService;
import com.pac.questionnaire.service.QuestionnaireQuestionRelService;
import com.pac.questionnaire.service.QuestionnaireService;
import com.pac.user.bean.UserBean;
import com.pac.weixin.service.WxChatAutoService;

/**
 * 问卷controller
 * 
 * @author lujun.chen
 * @version [版本号, 2015年2月13日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Controller
@Scope("prototype")
@RequestMapping("/questionnaire")
public class QuestionnaireController {

	private static Logger logger = Logger
			.getLogger(QuestionnaireController.class);

	@Autowired
	private QuestionnaireService questionnaireService;

	@Autowired
	private QuestionService questionService;

	@Autowired
	private QuestionOptionService questionOptionService;

	@Autowired
	private QuestionnaireQuestionRelService questionnaireQuestionRelService;

	@Autowired
	private QuestionnaireAnswerService questionnaireAnswerService;

	@Autowired
	private QuestionnaireDiagnosisService questionnaireDiagnosisService;

	@Autowired
	private QuestionnaireAnswerFileService questionnaireAnswerFileService;

	@Autowired
	private WxChatAutoService wxChatAutoService;

	@Autowired
	private QuestionnaireHospitalService questionnaireHospitalService;

	/**
	 * 分页查询问卷
	 * 
	 * @param request
	 * @param page
	 * @param rows
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/listData")
	@ResponseBody
	public Page queryQuestionnaireList(HttpServletRequest request, int page,
			int rows, QuestionnaireBean questionnaireBean) {
		// 设置每页记录数
		PageContext.getContext().setPageSize(rows);
		// 跳转到指定页
		PageContext.getContext().gotoPage(page);

		HttpSession session = request.getSession();
		UserBean userBean = (UserBean) session
				.getAttribute(SessionKeyContent.SESSION_KEY_OBJ_USER_BEAN);
		questionnaireBean.setUserId(userBean.getId());

		List<QuestionnaireBean> questionnaires = null;

		try {
			questionnaires = questionnaireService
					.queryQuestionnaire(questionnaireBean);
		} catch (LogicException ex) {
			logger.error("列表查询问卷出错：" + ex.getMessage());
		} catch (Exception ex) {
			logger.error("列表查询问卷出错：" + ex);
		}

		Page currentPage = new Page();
		// 总行数
		int totlaRols = PageContext.getContext().getTotal();
		currentPage.setTotal(totlaRols);
		currentPage.setRows(questionnaires);

		return currentPage;
	}

	/**
	 * 查询问卷下的问题
	 * 
	 * @param page
	 * @param rows
	 * @param questionnaireId
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/question/list")
	@ResponseBody
	public Page queryQuestionnaireQuestions(int page, int rows,
			String questionnaireId) {
		PageContext.getContext().setPageSize(rows);
		PageContext.getContext().gotoPage(page);

		List<QuestionBean> questionList = questionService
				.queryQuestionByQuestionnaireId(questionnaireId);

		Page currentPage = new Page();
		// 总行数
		int totlaRols = PageContext.getContext().getTotal();
		currentPage.setTotal(totlaRols);
		currentPage.setRows(questionList);

		return currentPage;
	}

	/**
	 * 查询问卷所属医院列表
	 * 
	 * @param questionnaireHospitalBean
	 * @param page
	 * @param rows
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/hospital/list")
	@ResponseBody
	public List<QuestionnaireHospitalBean> queryQuestionnaireHospital(
			QuestionnaireHospitalBean questionnaireHospitalBean) {

		return questionnaireHospitalService
				.queryQuestionnaireHospital(questionnaireHospitalBean);

	}

	/**
	 * 选择医院
	 * 
	 * @param questionnaireId
	 * @param memberIds
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/hospital/check")
	@ResponseBody
	public Map<String, Object> checkHospital(String questionnaireId,
			String memberIds) {
		boolean result = true;
		String msg = "操作成功";

		try {
			questionnaireHospitalService.checkHospital(questionnaireId,
					memberIds);
		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			result = false;
			msg = "系统内部错误";
			logger.error("选择医院出错，" + ex);
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", result);
		map.put("msg", msg);

		return map;
	}

	/**
	 * 删除问卷
	 * 
	 * @param questionnaireId
	 *            问卷ID
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/delete")
	@ResponseBody
	public Map<String, Object> delQuestionnaire(String questionnaireId) {
		boolean result = true;
		String msg = "操作成功";
		try {
			QuestionnaireBean questionnaireBean = new QuestionnaireBean();
			questionnaireBean.setId(questionnaireId);
			questionnaireService.delQuestionnaire(questionnaireBean);
		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("result", result);
		map.put("msg", msg);

		return map;
	}

	/**
	 * 添加问卷
	 * 
	 * @param QuestionnaireBean
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/add")
	@ResponseBody
	public Map<String, Object> addQuestionnaire(HttpServletRequest request,
			QuestionnaireBean questionnaireBean) {

		HttpSession session = request.getSession();
		UserBean userBean = (UserBean) session
				.getAttribute(SessionKeyContent.SESSION_KEY_OBJ_USER_BEAN);

		boolean result = true;
		String msg = "操作成功";
		String questionnaireId = "";

		try {
			questionnaireBean.setUserId(userBean.getId());
			questionnaireId = questionnaireService
					.addQuestionnaire(questionnaireBean);
		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			logger.error("添加问卷出错：" + ex);
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);
		map.put("questionnaireId", questionnaireId);

		return map;
	}

	/**
	 * 修改问卷
	 * 
	 * @param questionnaireBean
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/edit")
	@ResponseBody
	public Map<String, Object> editQuestionnaire(
			QuestionnaireBean questionnaireBean) {
		boolean result = true;
		String msg = "操作成功";

		try {
			result = questionnaireService
					.updateQuestionnaire(questionnaireBean);
		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			logger.error("修改问卷出错，" + ex);
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);

		return map;
	}

	/**
	 * 保存问卷问题
	 * 
	 * @param request
	 * @param question
	 * @param questionOptionsDes
	 *            问题选项描述，多个用@#@分割
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/question/add")
	@ResponseBody
	public Map<String, Object> addQuestionOption(HttpServletRequest request,
			QuestionBean question, String questionOptionsDes) {
		boolean result = true;
		String msg = "操作成功";

		try {

			// 设置创建人
			HttpSession session = request.getSession();
			UserBean userBean = (UserBean) session
					.getAttribute(SessionKeyContent.SESSION_KEY_OBJ_USER_BEAN);
			question.setUserId(userBean.getId());

			// 解析问题选项
			if (!StringTools.isNull(questionOptionsDes)) {
				String[] questionOptions = questionOptionsDes.split("@#@");
				List<QuestionOptionBean> optionList = new ArrayList<QuestionOptionBean>();
				for (String option : questionOptions) {
					QuestionOptionBean questionOptionBean = new QuestionOptionBean();
					questionOptionBean.setDescription(option);
					optionList.add(questionOptionBean);
				}
				question.setQuestionOptions(optionList);
			}

			questionService.addQuestion(question);

		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			logger.error("添加问卷问题出错，" + ex);
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);

		return map;
	}

	/**
	 * 修改问卷问题
	 * 
	 * @param request
	 * @param question
	 * @param questionOptionsDes
	 *            问题选项描述，多个用@#@分割
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/question/edit")
	@ResponseBody
	public Map<String, Object> editQuestionOption(HttpServletRequest request,
			QuestionBean question, String questionOptionsDes) {
		boolean result = true;
		String msg = "操作成功";

		try {
			// 解析问题选项
			if (!StringTools.isNull(questionOptionsDes)) {
				String[] questionOptions = questionOptionsDes.split("@#@");
				List<QuestionOptionBean> optionList = new ArrayList<QuestionOptionBean>();
				for (String option : questionOptions) {
					QuestionOptionBean questionOptionBean = new QuestionOptionBean();
					questionOptionBean.setDescription(option);
					optionList.add(questionOptionBean);
				}
				question.setQuestionOptions(optionList);
			}

			questionService.updateQuestion(question);

		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			logger.error("修改问卷问题出错，" + ex);
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);

		return map;
	}

	/**
	 * 删除问卷问题
	 * 
	 * @param questionId
	 *            问题ID
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/question/del")
	@ResponseBody
	public Map<String, Object> delQuestionOption(
			QuestionnaireQuestionRelBean qqRelBean) {
		boolean result = true;
		String msg = "操作成功";

		try {
			result = questionnaireQuestionRelService
					.delQuestionnaireQuestionRel(qqRelBean);

			if (result) {
				// 如果问题未绑定其他问卷，则把问题也删除了
				int num = questionnaireQuestionRelService
						.countQuestionnaireQuestion(qqRelBean);
				if (num == 0) {
					QuestionBean questionBean = new QuestionBean();
					questionBean.setId(qqRelBean.getQuestionId());
					questionService.delQuestion(questionBean);
				}
			}

		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			logger.error("删除问卷问题出错，" + ex);
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);

		return map;
	}

	/**
	 * 进入编辑问卷页面
	 * 
	 * @param questionnaireId
	 *            问卷ID
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/toedit")
	public ModelAndView toEditQuestionnaire(String questionnaireId) {

		QuestionnaireBean questionnaireBean = new QuestionnaireBean();
		questionnaireBean.setId(questionnaireId);
		questionnaireBean = questionnaireService
				.findQuestionnaire(questionnaireBean);

		ModelAndView mov = new ModelAndView();
		mov.addObject("questionnaireBean", questionnaireBean);
		mov.setViewName("questionnaire/questionnaire");
		return mov;
	}

	/**
	 * 进入编辑问题页面
	 * 
	 * @param questionid
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/question/option/list")
	@ResponseBody
	public List<QuestionOptionBean> queryQuestionOption(String questionId) {

		QuestionOptionBean questionOptionBean = new QuestionOptionBean();
		questionOptionBean.setQuestionId(questionId);

		return questionOptionService.queryQuestionOption(questionOptionBean);
	}

	/**
	 * 获取问卷答卷问题回答
	 * 
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/question/answer/get")
	@ResponseBody
	public Map<String, Object> getQuestionAnswer(String questionnaireId,
			String questionId, String answerId) {
		boolean result = true;
		String msg = "操作成功";
		List<QuestionnaireAnswerBean> answerList = null;

		try {
			QuestionnaireAnswerBean questionnaireAnswerBean = new QuestionnaireAnswerBean();
			questionnaireAnswerBean.setQuestionnaireId(questionnaireId);
			questionnaireAnswerBean.setQuestionId(questionId);
			questionnaireAnswerBean.setAnswerId(answerId);
			answerList = questionnaireAnswerService
					.queryQuestionnaireAnswer(questionnaireAnswerBean);

		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);
		map.put("answer", answerList);

		return map;
	}

	/**
	 * 列表查询答卷
	 * 
	 * @param request
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/answer/list")
	@ResponseBody
	public Page queryQuestionnaireDiagnosis(HttpServletRequest request,
			int page, int rows,
			QuestionnaireDiagnosisBean questionnaireDiagnosisBean) {

		// 设置每页记录数
		PageContext.getContext().setPageSize(rows);
		// 跳转到指定页
		PageContext.getContext().gotoPage(page);

		HttpSession session = request.getSession();
		UserBean userBeans = (UserBean) session
				.getAttribute(SessionKeyContent.SESSION_KEY_OBJ_USER_BEAN);

		if (null == questionnaireDiagnosisBean) {
			questionnaireDiagnosisBean = new QuestionnaireDiagnosisBean();
		}
		questionnaireDiagnosisBean.setDoctorUserId(userBeans.getId());
		questionnaireDiagnosisBean
				.setState(QuestionnaireKeyContent.QUESTIONNAIRE_DIAGNOSIS_STATE_NORMAL);
		List<QuestionnaireDiagnosisBean> diagnosisList = questionnaireDiagnosisService
				.queryQuestionnaireDiagnosis(questionnaireDiagnosisBean);

		Page currentPage = new Page();
		// 总行数
		int totlaRols = PageContext.getContext().getTotal();
		currentPage.setTotal(totlaRols);
		currentPage.setRows(diagnosisList);

		return currentPage;

	}

	/**
	 * 进入答卷详细页面
	 * 
	 * @param questionnaireId
	 *            问卷ID
	 * @param answerId
	 *            答卷ID
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/answer/detail")
	public ModelAndView questionnaireDetail(String questionnaireId,
			String answerId) {
		ModelAndView mov = new ModelAndView();
		mov.setViewName("questionnaire/answer_questionnaire_" + questionnaireId);
		mov.addObject("questionnaireId", questionnaireId);
		mov.addObject("answer_id", answerId);
		mov.addObject("goback", true);

		return mov;
	}

	/**
	 * 答卷详细
	 * 
	 * @param questionnaireId
	 * @param answerId
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/answer/view")
	public ModelAndView answerView(String questionnaireId, String answerId,
			boolean goback, String questionnaireType) {
		ModelAndView mov = new ModelAndView();

		mov.setViewName("questionnaire/answer_questionnaire");
		List<QuestionBean> questions = questionService
				.queryQuestionByQuestionnaireId(questionnaireId);
		mov.addObject("questions", questions);
		mov.addObject("answerId", answerId);
		mov.addObject("questionnaireId", questionnaireId);
		mov.addObject("goback", goback);
		mov.addObject("questionnaireType", questionnaireType);

		return mov;
	}

	/**
	 * 医生诊断
	 * 
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/diagnosis")
	@ResponseBody
	public Map<String, Object> questionnaireDiagnosis(
			QuestionnaireDiagnosisBean questionnaireDiagnosisBean) {

		boolean result = true;
		String msg = "";
		Map<String, String> resMap = new HashMap<String, String>();

		try {
			resMap = questionnaireDiagnosisService
					.questionnaireDiagnosis(questionnaireDiagnosisBean);
			result = true;
			msg = "操作成功";
		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {
			logger.error("问卷诊断出错，" + ex);
			result = false;
			msg = "系统内部错误";
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);
		map.put("openId", resMap.get("openId"));
		map.put("content", resMap.get("content"));
		return map;
	}

	@RequestMapping("/diagnosis/get")
	@ResponseBody
	public QuestionnaireDiagnosisBean findDiagnosis(String diagnosisId,
			String openId, String questionnaireId) {
		QuestionnaireDiagnosisBean questionnaireDiagnosisBean = new QuestionnaireDiagnosisBean();
		questionnaireDiagnosisBean.setId(diagnosisId);
		questionnaireDiagnosisBean.setOpenId(openId);
		questionnaireDiagnosisBean.setQuestionnaireId(questionnaireId);
		return questionnaireDiagnosisService
				.findQuestionnaireDiagnosis(questionnaireDiagnosisBean);
	}

	/**
	 * 问卷获取附件
	 * 
	 * @param answerId
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/answer/files")
	@ResponseBody
	public List<QuestionnaireAnswerFileBean> queryAnswerFiles(String answerId) {

		QuestionnaireAnswerFileBean questionnaireAnswerFileBean = new QuestionnaireAnswerFileBean();
		questionnaireAnswerFileBean.setDiagnosisId(answerId);
		List<QuestionnaireAnswerFileBean> answerFiles = questionnaireAnswerFileService
				.queryQuestionnaireAnswerFile(questionnaireAnswerFileBean);

		return answerFiles;
	}

	/**
	 * 修改答卷
	 * 
	 * @param request
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/answer/edit")
	@ResponseBody
	public Map<String, Object> editAnswer(HttpServletRequest request) {
		Map<String, Object> map = new HashMap<String, Object>();

		try {
			Map<String, String[]> mapAnswer = request.getParameterMap();
			questionService.editQuestion(mapAnswer);

			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, true);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, "操作成功");
		} catch (LogicException ex) {
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, false);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG,
					ex.getMessage());
		} catch (Exception ex) {
			logger.error("修改答卷出错，" + ex);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, false);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, "系统内部错误");
		}

		return map;
	}

	/**
	 * 删除答卷
	 * 
	 * @param answerId
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/answer/delete")
	@ResponseBody
	public Map<String, Object> delAnswer(String answerId) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			QuestionnaireDiagnosisBean questionnaireDiagnosisE = new QuestionnaireDiagnosisBean();
			questionnaireDiagnosisE.setId(answerId);
			questionnaireDiagnosisE
					.setState(QuestionnaireKeyContent.QUESTIONNAIRE_DIAGNOSIS_STATE_DEL);
			questionnaireDiagnosisService
					.updateQuestionnaireDiagnosis(questionnaireDiagnosisE);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, true);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, "操作成功");
		} catch (LogicException ex) {
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, false);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG,
					ex.getMessage());
		} catch (Exception ex) {
			logger.error("删除答卷出错，" + ex);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, false);
			map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, "系统内部错误");
		}

		return map;

	}

	/**
	 * 删除问卷关联的医院
	 * 
	 * @param questionnaireHospitalId
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/hospital/del")
	@ResponseBody
	public Map<String, Object> delQuestionnaireHospital(
			QuestionnaireHospitalBean questionnaireHospitalBean) {

		boolean result = true;
		String msg = "操作成功";

		try {
			questionnaireHospitalService
					.delQuestionnaireHospital(questionnaireHospitalBean);
		} catch (LogicException ex) {
			result = false;
			msg = ex.getMessage();
		} catch (Exception ex) {

			result = false;
			msg = "系统内部错误";
			logger.error("删除医院出错，" + ex);
		}

		Map<String, Object> map = new HashMap<String, Object>();
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT, result);
		map.put(MsgKeyContent.PAGE_AJAX_OPERATION_RESULT_MSG, msg);
		return map;
	}

	/**
	 * 页面跳转
	 * 
	 * @param pageName
	 * @return
	 * @see [类、类#方法、类#成员]
	 */
	@RequestMapping("/gotoPage")
	public ModelAndView gotoPage(HttpServletRequest request, String pageName,
			String userId) {
		ModelAndView mov = new ModelAndView();
		mov.setViewName("questionnaire/" + pageName);
		mov.addObject("userId", userId);

		Map<String, String[]> map = request.getParameterMap();
		Set<String> keysets = map.keySet();
		for (String key : keysets) {
			String paramV = map.get(key)[0];
			mov.addObject(key, paramV);
		}

		return mov;
	}

}
